{{extend '../views/layout.html'}} {{block 'title'}}日志{{/block}} {{block 'content'}}
<style>
    #list{
        margin: 0 auto;
        width: 1000px;
    }
    .item{
        margin: 10px 0;
        word-break: break-all;
        border: solid 1px #ccc;
    }
</style>
<button id="btn1">按钮</button>
<div id="list">
   
</div>
<script src="/js/socket.io.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
    $(function(){
        var list=$("#list");
        var socket = io(window.location.origin,{
            query:{
                token:"client"
            }
        });
        socket.on('connect', function () { 
        });
        socket.on('log', function (data) {
            
            if(data.constructor==Array){
                console.log(...data);return;
                for (var index = 0; index < data.length; index++) {
                    var item = data[index];
                    list.append("<div class='item'>"+JSON.stringify(item)+"</div>");
                }
            }else{
                console.log(data);return;
                list.append("<div class='item'>"+JSON.stringify(data)+"</div>");
            }
            $(window).scrollTop(list.height());
         });

         $("#btn1").click(function(){
         });
    })
</script> {{/block}}